Skip to content

[FE] Pahmi Alifya Bahri - pahmi1998@gmail.com - #299

Open
pahmi-alifya wants to merge 4 commits into
99techteam:mainfrom
pahmi-alifya:main
Open

[FE] Pahmi Alifya Bahri - pahmi1998@gmail.com#299
pahmi-alifya wants to merge 4 commits into
99techteam:mainfrom
pahmi-alifya:main

Conversation

@pahmi-alifya

Copy link
Copy Markdown

Summary

Solutions for the 99Tech code challenge, applying for the Frontend Engineer
role. Problems 1–3 are attempted (Problems 4–5 are out of scope for this role
and left untouched).

  • Problem 1 — three sum_to_n implementations (loop, closed-form formula,
    recursion) plus a runTestCases() helper that checks all three against a
    shared set of inputs.
  • Problem 2 — a currency swap form (React + TypeScript + Vite) using live
    prices and real token icons, with input validation and a simulated submit
    flow.
  • Problem 3 — a written audit of the provided "Messy React" snippet's
    bugs/inefficiencies, plus a refactored version.

Problem 1 — Three ways to sum to n

src/problem1/sum_to_n.js

  • sum_to_n_a: iterative loop — O(n) time, O(1) space.
  • sum_to_n_b: Gauss' formula n*(n+1)/2 — O(1) time, O(1) space.
  • sum_to_n_c: recursion — O(n) time, O(n) call-stack space.
  • runTestCases() runs all three against [0, 1, 5, 10, 100, 1000] and
    cross-checks the loop/formula versions against much larger values
    (1_000_000, 12345678); the recursive version is intentionally skipped
    for those, since it would overflow the call stack.

Run: node src/problem1/sum_to_n.js

Problem 2 — Fancy Form (currency swap)

src/problem2/ — Vite + React + TypeScript.

  • Fetches live prices from interview.switcheo.com/prices.json; the feed has
    duplicate/stale rows per currency, so only the latest positive-price entry
    per currency is kept. A bundled snapshot (src/prices.json) is the fallback
    if the live fetch fails.
  • Token icons pulled from Switcheo/token-icons;
    a currency without a matching icon falls back to an initials badge.
  • Output amount is derived live from the exchange rate — no separate
    "calculate" step.
  • Validation: amount must be a positive number; the two sides can't be the
    same token (enforced in the token picker itself).
  • ⇅ button reverses the swap direction, carrying the current output amount
    over as the new input.
  • Submit is simulated (setTimeout) since there's no real backend, so the
    loading spinner on the submit button is visible before a success message.
  • Form state/logic lives in hooks/useSwapForm.ts; SwapForm.tsx is purely
    presentational.

Run: cd src/problem2 && npm install && npm run dev

Problem 3 — Messy React

src/problem3/analysis.md

12 issues identified, including a couple of real bugs (an undefined
lhsPriority reference, and an inverted amount filter that keeps
zero/negative balances instead of positive ones), plus inefficiencies
(unstable getPriority, unnecessary useMemo dependency, a dead
formattedBalances variable computed but never used, key={index} on a
reorderable list, etc.). A refactored version is included with an explanation
of each change.

Assumptions

  • Problem 1: n >= 0, consistent with "sum to n" having no natural meaning
    for negative n; result stays under Number.MAX_SAFE_INTEGER per the spec.
  • Problem 2: no real backend exists, so submission is mocked; WBTC/ETH
    style live prices are trusted as-is from the given endpoint without
    additional slippage/fee modeling.

… price fetching

- Add SwapForm component for handling token swaps
- Create TokenSelect component for selecting currencies
- Implement TokenIcon component for displaying token icons
- Add CSS styles for the swap interface
- Introduce hooks for managing swap form state and fetching prices
- Add fallback prices for offline usage
- Create utility functions for formatting amounts and loading prices
- Set up TypeScript configuration for the project
- Include SVG icon for wstETH token
- Remove unused script file and legacy styles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant